# coding:utf-8
import urllib2
import json
import datetime
import subprocess
import time


def send_sms(mobile,message):
    data = {
         "smsID": "6666666",
         "smsContent": message,
         "sMobile": mobile,
         "serviceType": "1"}
    headers = {'Content-Type':'application/json'}
    url = 'http://ser-nginx.com:9103/send/sendSMS'
    request = urllib2.Request(url=url,headers=headers,data=json.dumps(data))
    urllib2.urlopen(request)


def get_command(path,keyword):
    date = datetime.date.today().strftime('%Y%m%d')
    command = "ls %s|grep %s%s |wc -l" % (path,keyword,date)
    #print command
    return command


if __name__ == '__main__':
    path = "/home/sftp/original/invest" 
    keyword = "0069_"
    command = get_command(path,keyword)
    file_numbers = subprocess.check_output(command,shell=True)

    qr_path = "/home/sftp/upload/qr"
    qr_keyword = "0069_"
    qr_command = get_command(qr_path,qr_keyword)
    qr_number = subprocess.check_output(qr_command,shell=True)

    date = datetime.date.today().strftime('%Y-%m-%d')
    message = "%s日监控：生成文件个数：%s,返回确认文件：%s  from wuyang monit" % (date,file_numbers,qr_number) 
    print message.replace("\n", "")

    mobiles = ['11111111111','111111111']
    for mobile_number in mobiles:
        try:
            send_sms(mobile_number,message.replace("\n", ""))
            print "发送" + mobile_number + "短信成功"
        except Exception as e:
            print "发送" + mobile_number + "短信失败:" + e
        time.sleep(1)






















